package com.enthusiasm.view;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.view.MotionEvent;

import com.enthusiasm.constants.AbstractSurfaceView;
import com.enthusiasm.constants.BitmapManager;
import com.enthusiasm.constants.SoundManager;
import com.enthusiasm.engine.MyButton;
import com.enthusiasm.engine.MyRect;
import com.enthusiasm.frame.GameModeActivity;
import com.enthusiasm.frame.GameModeFiveActivity;

public class GameModeFiveView extends AbstractSurfaceView{
	private Rect screenRect;
	private MyRect backRect;
	private ArrayList<MyRect> levelRect;
	private Bitmap bmpBackground;
	private Bitmap bmpBack01;
	private Bitmap bmpBack02;
	private Bitmap bmpLevelLock;
	private MyButton back;

	public GameModeFiveView(Context context) {
		super(context);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		back.onTouchEvent(event);
		return true;
	}

	@Override
	public void draw() {
		canvas.drawBitmap(bmpBackground, null, screenRect, paint);
		back.draw(canvas, paint);
		for(int i=0; i< levelRect.size(); i++){
			canvas.drawBitmap(bmpLevelLock, null, levelRect.get(i),paint);
		}
	}

	@Override
	public void logic() {
	}

	@Override
	public void initBitmap() {
		BitmapManager.getInstance(context).initMode05Bitmap();
		bmpBackground = BitmapManager.getInstance(context).bmpScreen05;
		bmpBack01 = BitmapManager.getInstance(context).bmpBack01;
		bmpBack02 = BitmapManager.getInstance(context).bmpBack02;
		bmpLevelLock = BitmapManager.getInstance(context).bmpLevelBg;
		back = new MyButton(bmpBack01,bmpBack02) {
			@Override
			public void doClick() {
				SoundManager.getInstance(context).playSoundClick();
				Intent intent  = new Intent(context,GameModeActivity.class);
				intent.putExtra("position", 5);
				context.startActivity(intent);
				((GameModeFiveActivity)context).finish();
				((GameModeFiveActivity)context).overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
			}
		};
	}

	@Override
	public void initRect() {
		screenRect = new Rect(0, 0, screenW, screenH);
		backRect = new MyRect(screenW/40, screenH/30, screenW/10,screenH/6);
		back.setRect(backRect);
		levelRect = new ArrayList<MyRect>();
		for(int i = 0; i<5; i++){
			MyRect level = new MyRect(screenW/20+i*screenW/5, screenH/4, screenW/10, screenH/6);
			levelRect.add(level);
		}
		for(int i = 0; i<5; i++){
			MyRect level = new MyRect(screenW/20+i*screenW/5, screenH/4+screenH/4, screenW/10, screenH/6);
			levelRect.add(level);
		}
		for(int i = 0; i<5; i++){
			MyRect level = new MyRect(screenW/20+i*screenW/5, screenH/4+screenH/2, screenW/10, screenH/6);
			levelRect.add(level);
		}
	}

	@Override
	public void releaseBitmap() {
		BitmapManager.getInstance(context).releaseMode05Bitmap();
	}
}

